#include <iostream>
#include <cstdio>
#define maxn 100000
using namespace std;

int main()
{
    int N, M;
    cin >> N;

    int l[maxn+2] = {0}, r[maxn+2] = {0};
    r[0] = 1; l[maxn+1] = 1;
    l[1] = 0; r[1] = maxn+1;
    for (int i=2; i<=N; ++i)
    {
        int k, o;
        scanf("%d%d", &k, &o);
        if (o == 1) {
            int R = r[k];
            r[k] = i; r[i] = R;
            l[R] = i; l[i] = k;
        }
        else {
            int L = l[k];
            l[k] = i; l[i] = L;
            r[L] = i; r[i] = k;
        }
    }
    cin >> M;
    for (int i=1; i<=M; ++i)
    {
        int del;
        scanf("%d", &del);
        int L = l[del]; int R = r[del];
        r[L] = R; l[R] = L;
    }
    if (r[0] == maxn+1) {printf("\n");return 0;}
    for (int i=r[0]; i!=l[maxn+1]; i=r[i])
    {
        printf("%d ", i);
    }
    printf("%d\n", l[maxn+1]);
    return 0;
}
/*
4
1 0
2 1
1 0
2
3
3


*/
